package com.jingsheng.jingshengcity.mvp.ui.fragment.tab;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerClassifyFragmentComponent;
import com.jingsheng.jingshengcity.di.module.ClassifyFragmentModule;
import com.jingsheng.jingshengcity.mvp.contract.ClassifyFragmentContract;
import com.jingsheng.jingshengcity.mvp.presenter.ClassifyFragmentPresenter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.ClassifyBrandFragmentAdapter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.ClassifyFragmentAdapter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.ClassifySubFragmentAdapter;
import com.jingsheng.jingshengcity.widgets.decoration.GridItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/5.
 */

public class ClassifyFragment extends BaseFragment<ClassifyFragmentPresenter> implements ClassifyFragmentContract.View {

    @NonNull
    @BindView(R.id.rv_left_list)
    RecyclerView mRvLeft;
    @NonNull
    @BindView(R.id.rv_classify_view)
    RecyclerView mRvClassify;
    @NonNull
    @BindView(R.id.rv_brand_view)
    RecyclerView mRvBrand;

    private List<String> mList = new ArrayList<>();
    private List<String> mSubList = new ArrayList<>();

    public static ClassifyFragment newInstance() {
        ClassifyFragment fragment = new ClassifyFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(AppComponent appComponent) {
        DaggerClassifyFragmentComponent
                .builder()
                .appComponent(appComponent)
                .classifyFragmentModule(new ClassifyFragmentModule(this))//请将ClassifyFragmentModule()第一个首字母改为小写
                .build()
                .inject(this);
    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_classify, container, false);
    }

    @Override
    public void initData() {
        initView();
        initAdapter();
    }

    @Override
    public void setData(Object data) {

    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    private void initAdapter() {

        mList.add("1");
        mList.add("2");
        mList.add("3");

        mSubList.add("1");
        mSubList.add("2");
        mSubList.add("3");
        mSubList.add("1");
        mSubList.add("2");
        mSubList.add("3");
        mSubList.add("3");

        ClassifyFragmentAdapter mClassifyFragmentAdapter = new ClassifyFragmentAdapter(R.layout.adapter_classify_item, mList);
        mClassifyFragmentAdapter.openLoadAnimation();
        mRvLeft.addItemDecoration(new GridItemDecoration(getActivity(), R.drawable.list_gray_devider));
        mRvLeft.setAdapter(mClassifyFragmentAdapter);

        ClassifySubFragmentAdapter mClassifySubFragmentAdapter = new ClassifySubFragmentAdapter(R.layout.adapter_classify_sub_item, mSubList);
        mClassifySubFragmentAdapter.openLoadAnimation();
        mRvClassify.setAdapter(mClassifySubFragmentAdapter);

        ClassifyBrandFragmentAdapter mClassifyBrandFragmentAdapter = new ClassifyBrandFragmentAdapter(R.layout.adapter_classify_sub_item, mSubList);
        mClassifyBrandFragmentAdapter.openLoadAnimation();
        mRvBrand.setAdapter(mClassifyBrandFragmentAdapter);

    }

    private void initView() {
        mRvLeft.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRvClassify.setLayoutManager(new GridLayoutManager(getActivity(), 3));
        mRvBrand.setLayoutManager(new GridLayoutManager(getActivity(), 3));
    }

}